<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="./../template/WorkspaceTemplate.xhtml"
                xmlns:c="http://java.sun.com/jsp/jstl/core"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.prime.com.tr/ui"
                xmlns:f="http://java.sun.com/jsf/core">

    <ui:define name="top">
        
    </ui:define>

    <ui:define name="left">
    </ui:define>

    <ui:define name="right">
       
    </ui:define>

    <ui:define name="content">
        <h:form prependId="false">
            <p:messages id="msgs" showDetail="true"/>
            <p:dataTable var="role" value="#{userRoleManagerBean.allRoles}" id="viewRoles">
                <f:facet name="header">
                    Edit Security Roles
                </f:facet>

                <p:column headerText="Role Name" 
                          filterBy="#{role.roleName}">
                    <h:outputText value="#{role.roleName}"/>
                </p:column>

                <p:column headerText="Department" 
                          filterBy="#{role.department}">
                    <h:outputText value="#{role.department}"/>
                </p:column>

                <p:column headerText="Access Rights" >
                    <p:commandButton id="edit#{role.id}" value="Change Access Rights" onsuccess ="dlg2.show()" update="displayMulti msgs" ajax="true"
                                     action="#{userRoleManagerBean.initSelectedAccessRights(role.id)}"/>
                </p:column>

                <p:column headerText="Edit Option">
                    <p:commandButton id="editRole#{role.id}" value="Edit" ajax="false"
                                     action="#{userRoleManagerBean.editRole(role.id)}"/>
                </p:column>
            </p:dataTable>

            <p:dialog id="updateRightsDlg" widgetVar="dlg2" header="Update Access Rights for #{userRoleManagerBean.selectedRole.roleName}"
                      width="700" height="400" showEffect="flip" hideEffect="flip">
                <p:dataTable id="displayMulti" var="ar" value="#{userRoleManagerBean.allAccessRights}"
                             selection="#{userRoleManagerBean.selectedAccessRights}"
                             style="width: 100%"
                             widgetVar="ars">
                    <f:facet name="header">
                        <p:outputPanel>
                            <h:outputText value="Search all fields:" />
                            <h:inputText id="globalFilter" onkeyup="ars.filter()" />
                        </p:outputPanel>
                    </f:facet>

                    <p:column selectionMode="multiple" style="width: 2%" />

                    <p:column headerText="Method Name" style="width: 23%"
                              filterBy="#{ar.methodName}"
                              sortBy="#{ar.methodName}">
                        <h:outputText value="#{ar.methodName}"/>
                    </p:column>

                    <p:column headerText="Method Path" style="width: 50%"
                              sortBy="#{ar.methodPath}"
                              filterBy="#{ar.methodPath}">
                        <h:outputText value="#{ar.methodPath}"/>
                    </p:column>

                    <p:column headerText="Method Category" style="width: 25%"
                              filterBy="#{ar.methodCategory}"
                              sortBy="#{ar.methodCategory}">
                        <h:outputText value="#{ar.methodCategory}"/>
                    </p:column>

                    <f:facet name="footer">
                        <p:commandButton value="Save"
                                         actionListener="#{userRoleManagerBean.updateAccessRights}" update="left-menu-list displayMulti msgs"
                                         image="ui-icon ui-icon-save" oncomplete="dlg2.hide()" process="updateRightsDlg"/>
                    </f:facet>
                </p:dataTable>
            </p:dialog>

            <p:ajaxStatus>
                <f:facet name="start">
                    <h:graphicImage value="./../images/ajaxloading.gif"/>
                </f:facet>
                <f:facet name="complete">
                    <h:outputText value=""/>
                </f:facet>
            </p:ajaxStatus>
        </h:form>
    </ui:define>

    <ui:define name="bottom">
       
    </ui:define>

</ui:composition>
